﻿﻿/**
 *  
 */
define([
        "dojo/_base/declare","dojo/_base/lang","dojo/_base/array",
        "gistech/widgets/normalDialog/NormalDialog",
        "dojo/text!./templates/BookMarkEdit.html",
         "esri/layers/FeatureLayer","esri/graphic","esri/tasks/QueryTask", 
         "dojo/on","dojo/topic"],
        function(declare,lang,array,NormalDialog,template, FeatureLayer,Graphic,QueryTask ,on,topic
        		 ){
            return declare([NormalDialog],{
            	map:null,
                lcBodyClick:null,//单击body的事件句柄
                hasConfig:false,
                templateString:template,
                symbols:{},
                nowUserBookMarkNames:[],//当前所有书签名
                userBookMarkNames:[],//初始化查询所有书签名
                editBookName:null,//编辑前的书签名
                constructor:function (args) {
                	this.inherited(arguments); 
                	this.bName = args.bName;
                	this.bRemark = args.bRemark;
                	this.bID = args.bID;
                },
                
                resetAttr:function(){
                	this.count = 1;
                	if(this.lcBodyClick){
                		dojo.disconnect(this.lcBodyClick);
                	}
                	this.lcBodyClick = null;
                },

                postCreate:function () {
                	this.inherited(arguments);
                	this.setTitle("新增");
                    if(this.bName){
                    	 dojo.byId('bookMarkName').value = this.bName;
                    	 this.setTitle("编辑");
                    }
                    if(this.bRemark){
                   	 dojo.byId('bookMarkRemark').value = this.bRemark;
                   }
 
                    
                    on(this.bookMarkSaveBtn, "click",lang.hitch(this,this.createOrEditBMark));
                	on(this.bookMarkResetBtn,"click",lang.hitch(this,this._resetBookMark));
                	topic.subscribe("closeBookMarkEdit", lang.hitch(this, this.close));
                },

 
                createOrEditBMark:function(){
                	var name = dojo.byId('bookMarkName').value;
                	var remark = dojo.byId('bookMarkRemark').value;
                	if(name.trim()==''){
                		//TODO 长度控制
                		layer.msg("书签名称不能空!",{icon:2});
                		return;
                	}
                	topic.publish('saveBK',this.bID,name,remark);
                },
        		/**
        		 * 重置 
        		 */
                _resetBookMark:function(){
        			this._resetForm();
        			this._clearLayerAndTable();
        		},
        		
        		_resetForm:function(){
        			$('#bookMarkName',this.domNode).val('');
        			$('#bookMarkRemark',this.domNode).val('');
        		},

                startup:function () {
                    this.inherited(arguments);
                },
 
                //关闭事件
                onClose:function () {
                    this.destroy();
                }
                
                
            })
})